package com.sms.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.sms.common.A;
import com.sms.pojo.Products;
import com.sms.service.impl.ProductsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//商品信息修改
@WebServlet("/ProductsModify")
public class ProductsModifyController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ServletInputStream inputStream = request.getInputStream();
        String s = IoUtil.readUtf8(inputStream);
        JSONObject obj = JSONUtil.parseObj(s);
        Products product=new Products();
        BeanUtil.copyProperties(obj,product);
        ProductsServiceImpl service=new ProductsServiceImpl();
        service.updateById(product);
        service.getSqlSession().close();
        A r= A.success("商品信息修改成功");
        response.getWriter().write(JSONUtil.toJsonStr(r));
    }
}
